getUriForFile

open fun getUriForFile(@NonNull context: Context, @NonNull authority: String, @NonNull file: File): Uri(source)

Return a content URI for a given File. Specific temporary permissions for the content URI can be set with grantUriPermission, or added to an Intent by calling setData() and then setFlags(); in both cases, the applicable flags are FLAG_GRANT_READ_URI_PERMISSION and FLAG_GRANT_WRITE_URI_PERMISSION. A FileProvider can only return a contentUri for file paths defined in their <paths> meta-data element. See the Class Overview for more information.

Return

A content URI for the file.

Parameters

context

A Context for the current component.

authority

The authority of a FileProvider defined in a <provider> element in your app's manifest.

file

A File pointing to the filename for which you want a contentUri.

Throws

When the given File is outside the paths supported by the provider.


open fun getUriForFile(@NonNull context: Context, @NonNull authority: String, @NonNull file: File, @NonNull displayName: String): Uri(source)

Return a content URI for a given File. Specific temporary permissions for the content URI can be set with grantUriPermission, or added to an Intent by calling setData() and then setFlags(); in both cases, the applicable flags are FLAG_GRANT_READ_URI_PERMISSION and FLAG_GRANT_WRITE_URI_PERMISSION. A FileProvider can only return a contentUri for file paths defined in their <paths> meta-data element. See the Class Overview for more information.

Return

A content URI for the file.

Parameters

context

A Context for the current component.

authority

The authority of a FileProvider defined in a <provider> element in your app's manifest.

file

A File pointing to the filename for which you want a contentUri.

displayName

The filename to be displayed. This can be used if the original filename is undesirable.

Throws

When the given File is outside the paths supported by the provider.